﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DownloadBook {
    public partial class FrmDownload : Form {
        private List<ListViewItem> itemViewList = new List<ListViewItem>();
        private List<Content> list;
        private int firstItem = 0;
        public FrmDownload(List<Content> list) {
            InitializeComponent();
            this.list = list;
        }

        private void FrmDownload_Load(object sender, EventArgs e) {
            this.downloadListView.RetrieveVirtualItem += new RetrieveVirtualItemEventHandler(downloadListView_RetrieveVirtualItem);
            this.downloadListView.VirtualMode = true;
            this.downloadListView.VirtualListSize = list.Count;
        }

        private void downloadListView_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e) {
            //Caching is not required but improves performance on large sets.
            //To leave out caching, don't connect the CacheVirtualItems event 
            //and make sure myCache is null.

            //check to see if the requested item is currently in the cache
            if (itemViewList != null && e.ItemIndex >= firstItem && e.ItemIndex < firstItem + itemViewList.Count) {
                //A cache hit, so get the ListViewItem from the cache instead of making a new one.
                e.Item = itemViewList[e.ItemIndex - firstItem];
            } else {
                //A cache miss, so create a new ListViewItem and pass it back.
                int x = e.ItemIndex * e.ItemIndex;
                e.Item = new ListViewItem(x.ToString());
            }
        }
    }
}
